﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Controls;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class DSTDYARN : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        DSTDYARNData m_Data, m_DataX;
        public DataSet setUI=new DataSet();
        public DataSet dsParamaters;
        public DataRow dwABPOS;
        public DataRow dwVKPOS;
        public INTEXDBC INTEXDBC;
        private string fromshippingdate = "", endshippingdate = "";
        private DataRow dwUI;
        DataTable tableUI;
        private string fromdate = "", enddate = "";   
        #endregion
        public DSTDYARN()
        {
            InitializeComponent();
            this.Name = "工艺用纱表";
           
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            dsParamaters = (DataSet)dicParamater["dsParamaters"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new DSTDYARNData();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
            tableUI = new DataTable("UIData");
            tableUI.Columns.Add("ARTICLE", typeof(string));
            tableUI.Columns.Add("COLOR", typeof(string));
            tableUI.Columns.Add("COLORE", typeof(string));
            tableUI.Columns.Add("COLOR1", typeof(string));
            tableUI.Columns.Add("COLOR2", typeof(string));
            tableUI.Columns.Add("COLOR3", typeof(string));
            tableUI.Columns.Add("COLOR4", typeof(string));
            tableUI.Columns.Add("COLOR5", typeof(string));
            tableUI.Columns.Add("COLOR6", typeof(string));
            tableUI.Columns.Add("COLOR7", typeof(string));
            tableUI.Columns.Add("COLOR8", typeof(string));
            tableUI.Columns.Add("COLOR9", typeof(string));
            tableUI.Columns.Add("COLOR10", typeof(string));
            tableUI.Columns.Add("COLOR11", typeof(string));
            tableUI.Columns.Add("COLOR12", typeof(string));
            tableUI.Columns.Add("COLOR13", typeof(string));
            tableUI.Columns.Add("COLOR14", typeof(string));
            tableUI.Columns.Add("COLOR15", typeof(string));
            tableUI.Columns.Add("COLOR16", typeof(string));
            tableUI.Columns.Add("COLOR17", typeof(string));
            tableUI.Columns.Add("COLOR18", typeof(string));
            tableUI.Columns.Add("COLOR19", typeof(string));
            tableUI.Columns.Add("COLOR20", typeof(string));
        }

        private void InitDataBinding()
        {
             
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                dwUI = tableUI.NewRow(); 
                InitDataBinding();
                txtARTICLE.Focus();               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return;

        }
        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet setResult = new DataSet();            
                setUI.Clear();
                setUI.AcceptChanges();
                #region var
                string ARTICLE = txtARTICLE.Text.Trim();
                string COLOR = m_Data.Right("00"+txtCOLOR.Text.Trim(),2);
                string COLORE = m_Data.Right("00" + txtCOLORE.Text.Trim(), 2);
                string COLOR1 = m_Data.Right("00" + txtCOLOR1.Text.Trim(), 2);
                string COLOR2 = m_Data.Right("00" + txtCOLOR2.Text.Trim(), 2);
                string COLOR3 = m_Data.Right("00" + txtCOLOR3.Text.Trim(), 2);
                string COLOR4 = m_Data.Right("00" + txtCOLOR4.Text.Trim(), 2);
                string COLOR5 = m_Data.Right("00" + txtCOLOR5.Text.Trim(), 2);
                string COLOR6 = m_Data.Right("00" + txtCOLOR6.Text.Trim(), 2);
                string COLOR7 = m_Data.Right("00" + txtCOLOR7.Text.Trim(), 2);
                string COLOR8 = m_Data.Right("00" + txtCOLOR8.Text.Trim(), 2);
                string COLOR9 = m_Data.Right("00" + txtCOLOR9.Text.Trim(), 2);
                string COLOR10 = m_Data.Right("00" + txtCOLOR10.Text.Trim(), 2);
                string COLOR11 = m_Data.Right("00" + txtCOLOR11.Text.Trim(), 2);
                string COLOR12 = m_Data.Right("00" + txtCOLOR12.Text.Trim(), 2);
                string COLOR13 = m_Data.Right("00" + txtCOLOR13.Text.Trim(), 2);
                string COLOR14 = m_Data.Right("00" + txtCOLOR14.Text.Trim(), 2);
                string COLOR15 = m_Data.Right("00" + txtCOLOR15.Text.Trim(), 2);
                string COLOR16 = m_Data.Right("00" + txtCOLOR16.Text.Trim(), 2);
                string COLOR17 = m_Data.Right("00" + txtCOLOR17.Text.Trim(), 2);
                string COLOR18 = m_Data.Right("00" + txtCOLOR18.Text.Trim(), 2);
                string COLOR19 = m_Data.Right("00" + txtCOLOR19.Text.Trim(), 2);
                string COLOR20 = m_Data.Right("00" + txtCOLOR20.Text.Trim(), 2);
               
                #endregion

                dwUI["ARTICLE"] = ARTICLE;
                dwUI["COLOR"] = COLOR;
                dwUI["COLORE"] = COLORE;
                dwUI["COLOR1"] = COLOR1;
                dwUI["COLOR2"] = COLOR2;
                dwUI["COLOR3"] = COLOR3;
                dwUI["COLOR4"] = COLOR4;
                dwUI["COLOR5"] = COLOR5;
                dwUI["COLOR6"] = COLOR6;
                dwUI["COLOR7"] = COLOR7;
                dwUI["COLOR8"] = COLOR8;
                dwUI["COLOR9"] = COLOR9;
                dwUI["COLOR10"] = COLOR10;
                dwUI["COLOR11"] = COLOR11;
                dwUI["COLOR12"] = COLOR12;
                dwUI["COLOR13"] = COLOR13;
                dwUI["COLOR14"] = COLOR14;
                dwUI["COLOR15"] = COLOR15;
                dwUI["COLOR16"] = COLOR16;
                dwUI["COLOR17"] = COLOR17;
                dwUI["COLOR18"] = COLOR18;
                dwUI["COLOR19"] = COLOR19;
                dwUI["COLOR20"] = COLOR20;       
                setResult = m_Data.BuildDSTDYARNData(dwUI);
                setUI.Merge(setResult);
                dlgARTICLE.DataContext = setUI.Tables["ARTICLE"];
                dlgDYARN.DataContext = setUI.Tables["DYARN"];
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnPrintPreview_Click(object sender, RoutedEventArgs e)
        {
            return;
            m_DataX = new DSTDYARNData(dicParamater);
            m_DataX.exAgent._app.Visible = false;
            m_DataX.OracleDB = this.OracleDB;
            m_DataX.proxy = this.proxy;
            DSTDYARNReport m_rpt = new DSTDYARNReport(dicParamater);
            m_rpt.dsSource = setUI;
            m_rpt.PrintType = "OpenExcel";
            m_rpt.exAgent = m_DataX.exAgent;
            m_rpt.WriteExcelReport("EXCEL");
        }        
        private void txtART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter) return;
            btnQuery_Click(null,null);

        }
    }
}
